package com.bjar;

import java.util.LinkedList;

public class Node {
	public Node()
	{
		ID = 0;
		isHeadEmpty = true;
	}
	
	public Node(String val)
	{
		Value = val;
		ID++;
		length = val.length();
	}
	
	private String Value;
	private Node Parent;
	private LinkedList<Node> Children;
	private Integer ID;
	private Integer length;
	private Boolean isHeadEmpty;

	public Integer getLength() {
		return length;
	}

	public void setLength(Integer length) {
		this.length = length;
	}

	public Node getParent() {
		return Parent;
	}

	public void setParent(Node parent) {
		Parent = parent;
	}

	public LinkedList<Node> getChildren() {
		return Children;
	}

	public void AddChild(Node child) {
		Children.add(child);
	}
	
	public Node SuffixLinkParent()
	{
		//TODO
		return null;
	}

	public Integer getID() {
		return ID;
	}

	public void setID(Integer iD) {
		ID = iD;
	}

	public String getValue() {
		return Value;
	}

	public void setValue(String value) {
		Value = value;
	}
	
	public void Split(int index)
	{
		Children.add(new Node(Value.substring(index)));
		Value = Value.substring(0, index);		
	}
	
	public Boolean HeadIsEmpty()
	{
		return isHeadEmpty;
	}
	
	public static Boolean IsNewNode(String value)
	{
		return false;
	}
	
	public int slowScan(String compareString)
	{
		if(Value.length() > compareString.length())
		{
			for(int i = 0; i < Value.length(); i++)
			{
				if(Value.charAt(i) != compareString.charAt(i))
					return i;
			}
			return compareString.length();
		}
		else if(Value.length() == compareString.length())
		{
			return Value.length();
		}
		else
		{
			for(int i = 0; i < compareString.length(); i++)
			{
				if(Value.charAt(i) != compareString.charAt(i))
					return i;
			}
			return Value.length();
		}
			
	}

}
